

package es.realtimesystems.simplemulticast;
import java.net.*;

public class PruebaCanalUnicastReceptor implements CanalCallback
{
long contadorBytesRecibidos = 0;

  public PruebaCanalUnicastReceptor()
  {
  final String mn="PRUEBACANALUNICASTRECEPTOR()";
try{
  Address dirUcast = new Address (InetAddress.getByName ("192.168.0.7"),1048);


  CanalUnicast canalUcast = CanalUnicast.getInstance(dirUcast,null,null,null);
  canalUcast.setCallback (this,1);

  while (this.contadorBytesRecibidos < 32000)
  {
   Temporizador.sleep (100000);
   Thread.yield();
  }

 Log.log (mn,"Tiempo de Fin: " + Temporizador.tiempoActualEnMseg());

  }catch (java.net.UnknownHostException e)
   {
    Log.log (mn,""+e);
   }
  catch (java.io.IOException e)
   {
    Log.log (mn,""+e);
   }
  }

  public static void main(String[] args)
  {
   new PruebaCanalUnicastReceptor();
  }
  public void canalCallback(int arg, Buffer buf, Address src)
  {
    final String  mn = "canalCallback(int,Buffer,Address)";

/*    System.out.println ("Numero bytes recibidos: " + buf.getLength());
    this.contadorBytesRecibidos += buf.getLength();
    System.out.println ("Bytes acumulados: " + this.contadorBytesRecibidos);
    System.out.println ("Tiempo "+Temporizador.tiempoActualEnMseg());
  */

try{
    TPDUACK tpduACK = TPDUACK.parserBuffer (buf,src.toIPv4());
    System.out.println ("Recibido TPDU ACK: " + "\n" + tpduACK);
    }
    catch (PTMFExcepcion e) { System.out.println ("EXCEPCION: " + e);}
    catch (ParametroInvalidoExcepcion e) { System.out.println ("EXCEPCION: " + e);}
  }



}
